package com.shuwen.gcdj.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.shuwen.gcdj.common.constant.MemberCst;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject,"createId",String.class, MemberCst.LOGIN_USER_ID);
        this.strictInsertFill(metaObject,"updateId",String.class, MemberCst.LOGIN_USER_ID);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject,"createId",String.class, MemberCst.LOGIN_USER_ID);
        this.strictInsertFill(metaObject,"updateId",String.class, MemberCst.LOGIN_USER_ID);
    }


}
